import React from 'react'
// 引入路由组件
import { Route, Routes, Navigate } from 'react-router-dom';
// 引入路由表
import routers from './index';

function RouterView() {
    const ReactRouterRender = (arr) => {
        return arr.map((item, index) => {
            return <Route key={index} path={item.path} element={item.to ? <Navigate to={item.to} /> : <item.element></item.element>}>
                {
                    item.children && ReactRouterRender(item.children)
                }
            </Route>
        })
    }
    return <Routes>
        {
            routers && ReactRouterRender(routers)
        }
    </Routes>

}

export default RouterView